home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / DOANSI_2.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  5KB  |  230 lines

  1. /*
  2. **  DOANSI_2.C - OS-Specific ANSI screen code interpreter functions
  3. **
  4. **  From DRSK_105.LZH (ansi.c), hereby declared free for use for whatever
  5. **  purposes by author: Mark Kimes
  6. */
  7.  
  8. #ifdef OS2
  9.  
  10. #define INCL_DOS
  11. #define INCL_VIO
  12.  
  13. #include <os2.h>
  14.  
  15. int vidhandle = 0;  /* can be changed for AVIO */
  16.  
  17. void set_screensize (int reservedlines)
  18. {
  19.       VIOMODEINFO vm;
  20.  
  21.       vm.cb = sizeof(VIOMODEINFO);
  22.       VioGetMode(&vm, vidhandle);
  23.       maxx = vm.col;
  24.       maxy = vm.row - reservedlines;
  25.       realmaxx = maxx;
  26.       realmaxy = vm.row;
  27. }
  28.  
  29. void pos_hardcursor (int x,int y)
  30. {
  31.       VioSetCurPos(y,x,vidhandle);
  32. }
  33.  
  34. void hardcursor_off (void)
  35. {
  36.       VIOCURSORINFO vc;
  37.  
  38.       VioGetCurType(&vc,vidhandle);
  39.       vc.attr = -1;
  40.       VioSetCurType(&vc,vidhandle);
  41. }
  42.  
  43. void hardcursor_on (int x,int y)
  44. {
  45.       VIOCURSORINFO vc;
  46.  
  47.       VioGetCurType(&vc,vidhandle);
  48.       vc.attr = 0;
  49.       VioSetCurType(&vc,vidhandle);
  50.       VioSetCurPos(y,x,vidhandle);
  51. }
  52.  
  53. void put_char (char c, char attr, int x, int y)
  54. {
  55.       VioWrtCharStrAtt(&c,1,y,x,&attr,vidhandle);
  56. }
  57.  
  58. void scroll_up (int tx,int ty,int bx,int by,char attr)
  59. {
  60.       int attrib = ' ' | (attr << 8);
  61.  
  62.       VioScrollUp(ty,tx,by,bx,1,(char *)&attrib,vidhandle);
  63. }
  64.  
  65. void clearwindow (int tx,int ty,int bx,int by,char attr)
  66. {
  67.       int attrib = ' ' | (attr << 8);
  68.  
  69.       VioScrollUp(ty,tx,by,bx,-1,(char *)&attrib,vidhandle);
  70. }
  71.  
  72. void cleartoeol (int x,int y,int ex,char attr)
  73. {
  74.       int attrib = ' ' | (attr << 8);
  75.  
  76.       VioScrollUp(y,x,y,ex,-1,(char *)&attrib,vidhandle);
  77. }
  78.  
  79. #else
  80.  
  81. /* MS-DOS -- (urp) */
  82.  
  83. #include <dos.h>
  84.  
  85. #if !defined(MK_FP)
  86.  #define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
  87. #endif
  88.  
  89. static int far *vseg;
  90. int            realmaxy,realmaxx;
  91. char           usebios = 0; /* if true, output through BIOS */
  92.  
  93. int vmode (void)
  94. {
  95.       union REGS r;
  96.  
  97.       r.h.ah = 15;
  98.       r.x.bx = 0;
  99.       int86(0x10,&r,&r);
  100.       return r.h.al;
  101. }
  102.  
  103. void set_screensize (int reservedlines)
  104. {
  105.       union REGS   r;
  106.       unsigned int vbase;
  107.  
  108.       r.h.ah = 0x0f;
  109.       r.x.bx = 0;
  110.       int86 (0x10, &r, &r);
  111.       maxx = (int) r.h.ah;
  112.       if (maxx < 80)                                  /* gimme a break! */
  113.       {
  114.             r.x.ax = 0x0003;
  115.             int86(0x10,&r,&r);
  116.             maxx = 80;
  117.       }
  118.       realmaxx = maxx;
  119.       r.x.ax = 0x1130;
  120.       r.x.dx = maxy;
  121.       int86 (0x10, &r, &r);
  122.       realmaxy = maxy = (r.x.dx == 0) ? 25 : (r.x.dx + 1);
  123.       maxy -= reservedlines;
  124.       vbase = (vmode () == 7 ? 0xb000 : 0xb800);
  125.       vseg = MK_FP(vbase,0);        /* address of video ram as pointer */
  126. }
  127.  
  128. void pos_hardcursor (int x,int y)
  129. {
  130.       union REGS r;
  131.  
  132.       r.x.ax = 0x0200;
  133.       r.x.bx = 0;
  134.       r.x.dx = ((y << 8) & 0xff00) + x;
  135.       int86(0x10,&r,&r);
  136. }
  137.  
  138. void hardcursor_off (void)
  139. {
  140.       union REGS r;
  141.  
  142.       r.x.ax = 0x0200;
  143.       r.x.bx = 0;
  144.       r.x.dx = ((realmaxy << 8) & 0xff00);
  145.       int86(0x10,&r,&r);
  146. }
  147.  
  148. void hardcursor_on (int x,int y)
  149. {
  150.       union REGS r;
  151.  
  152.       r.x.ax = 0x0200;
  153.       r.x.bx = 0;
  154.       r.x.dx = ((y << 8) & 0xff00) + x;
  155.       int86(0x10,&r,&r);
  156. }
  157.  
  158. void put_char (char c, char attr, int x, int y)
  159. {
  160.       if(!usebios)
  161.       {
  162.             register int far *v;
  163.  
  164.              /* point v to right spot in vid RAM */
  165.  
  166.             v = vseg + ((y * realmaxx) + x);
  167.             *v = (c | (attr << 8));                   /* display */
  168.       }
  169.       else
  170.       {
  171.  
  172.             union REGS r;
  173.  
  174.             r.x.ax = 0x0200;
  175.             r.x.bx = 0;
  176.             r.x.dx = ((y << 8) & 0xff00) + x;
  177.             int86(0x10,&r,&r);
  178.             r.h.ah = 0x09;
  179.             r.h.bh = 0;
  180.             r.h.bl = attr;
  181.             r.x.cx = 1;
  182.             r.h.al = c;
  183.             int86(0x10,&r,&r);
  184.       }
  185. }
  186.  
  187. void scroll_up (int tx,int ty,int bx,int by,char attr)
  188. {
  189.       union REGS r;
  190.  
  191.       r.h.ah = 6;
  192.       r.h.al = 1;
  193.       r.h.bh = attr;
  194.       r.h.cl = tx;
  195.       r.h.ch = ty;
  196.       r.h.dl = bx;
  197.       r.h.dh = by;
  198.       int86(0x10,&r,&r);
  199. }
  200.  
  201. void clearwindow (int tx,int ty,int bx,int by,char attr)
  202. {
  203.       union REGS r;
  204.  
  205.       r.h.ah = 6;
  206.       r.h.al = 0;
  207.       r.h.bh = attr;
  208.       r.h.cl = tx;
  209.       r.h.ch = ty;
  210.       r.h.dl = bx;
  211.       r.h.dh = by;
  212.       int86(0x10,&r,&r);
  213. }
  214.  
  215. void cleartoeol (int x,int y,int ex,char attr)
  216. {
  217.       union REGS r;
  218.  
  219.       r.h.ah = 6;
  220.       r.h.al = 0;
  221.       r.h.bh = attr;
  222.       r.h.cl = x;
  223.       r.h.ch = y;
  224.       r.h.dl = ex;
  225.       r.h.dh = y;
  226.       int86(0x10,&r,&r);
  227. }
  228.  
  229. #endif
  230.